package com.ykj.controller;

import com.ykj.dto.Result;
import com.ykj.entity.User;
import com.ykj.service.UserServer;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author Y2014188432
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserServer userServer;

    @GetMapping("getCode")
    public Result getCode(@RequestParam("phone") String phone, HttpSession session){
        return userServer.getCode(phone,session);
    }


    @GetMapping("/getUser")
    public Result getUser(){
        System.out.println("调用");
        return Result.ok(userServer.getById(1));
    }

    @PostMapping("/loginByCode")
    public Result loginByCode(@RequestParam("phone") String phone,@RequestParam("code") String code){
        return userServer.loginByCode(phone,code);
    }

    @PostMapping("/loginByPw")
    public Result loginByPw(@RequestParam("phone") String phone,@RequestParam("password") String password){
        return userServer.loginByPw(phone,password);
    }

    @GetMapping("/getMsg")
    public Result getMsg(){
        return userServer.getMsg();
    }

    @PostMapping("/update")
    public Result updateUser(@RequestBody User user){
        return userServer.updateUser(user);
    }

    @PostMapping("/updatePassword")
    public Result updatePassword(@RequestParam("password") String  password,@RequestParam("passwordNew") String passwordNew){
        return userServer.updatePassword(password,passwordNew);
    }

    @GetMapping("/getMessageById")
    public Result getMessageById(String id){
        return userServer.getMessageById(id);
    }

    @GetMapping("/getUserByPower")
    public Result getUserByPower(){
        return userServer.getUserByPower();
    }

    @PostMapping("/changePower")
    public Result changePower(@RequestBody User user){
        return userServer.changePower(user);
    }

}
